package com.morn.fanfou.model;

import java.util.Map;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;

public abstract class BaseModel {

	public static final String AUTHORITY = "com.renren.mobile.base";
	public final String CONTENT_ITEM_TYPE_BASE = "vnd.android.cursor.item/";
	public final String CONTENT_TYPE_BASE = "vnd.android.cursor.dir/";
	public final String DEFAULT_SORT_ORDER = "_id ASC";
	public String tableName;

	public int bulkInsert(Uri uri, ContentValues[] values, SQLiteOpenHelper openHelper, Context context) {
		SQLiteDatabase localSQLiteDatabase = openHelper.getWritableDatabase();
		int insertNum = 0;
		try {
			localSQLiteDatabase.beginTransaction();
			int length = values.length;
			for (int i = 0; i < length; i++) {
				long row = localSQLiteDatabase.insert(this.tableName, null, values[i]);
				if (row != -1) {
					insertNum++;
				}
			}
			localSQLiteDatabase.setTransactionSuccessful();
			if (insertNum > 0) {
				context.getContentResolver().notifyChange(uri, null);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			localSQLiteDatabase.endTransaction();
		}

		return insertNum;
	}

	public int delete(Uri uri, String selection, String[] selectionArgs, SQLiteOpenHelper openHelper, Context context) {
		SQLiteDatabase localSQLiteDatabase = openHelper.getWritableDatabase();
		int num = localSQLiteDatabase.delete(this.tableName, selection, selectionArgs);
		context.getContentResolver().notifyChange(uri, null);
		return num;
	}

	public abstract Class<?> getColumnClass();

	protected String getContentItemType() {
		return "vnd.android.cursor.item/" + this.tableName;
	}

	protected String getContentType() {
		return "vnd.android.cursor.dir/" + this.tableName;
	}

	public abstract String getCreateSql();

	public Map<?, ?> getProjectMap(Class<?> paramClass) {
		return null;
	}

	public String getType(Uri uri) {
		return null;
	}

	public Uri getUri() {
		return Uri.parse("content://com.renren.mobile.base/" + this.tableName);
	}

	public void initProjectMap(Class<?> paramClass) {

	}

	public Uri insert(Uri uri, ContentValues values, SQLiteOpenHelper openHelper, Context context) {
		return null;
	}

	public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder,
			SQLiteOpenHelper openHelper, Context context) {
		SQLiteQueryBuilder localSQLiteQueryBuilder = new SQLiteQueryBuilder();
		localSQLiteQueryBuilder.setTables(this.tableName);

		return null;
	}

	public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs,
			SQLiteOpenHelper openHelper, Context getContext) {
		return 0;
	}
}
